//|||||||||||||||||||||||||||||||||||||||||||||||

#ifndef GAME1_STATE_HPP
#define GAME1_STATE_HPP

//|||||||||||||||||||||||||||||||||||||||||||||||

#include "AppState.hpp"

#include "DotSceneLoader.hpp"

#include <OgreSubEntity.h>
#include <OgreMaterialManager.h>
#include <string>

//|||||||||||||||||||||||||||||||||||||||||||||||

const float PLAYER_HEIGHT = 35.0f;
const float PLAYER_SPEED = 1.4f;
const float GRAVITY = -0.0015f;
const float JUMPING_SPEED = 0.70f;
const float MAX_FALLING_SPEED = -2.0f;
const float PLAYER_OFFSET = 8.0f;
const float PROGRESS1_PER_MILISECOND = -0.000002f;
const float PROGRESS1_PER_BONUS = 0.05f;
const float PROGRESS1_PER_HAZARD = -0.05f;

//|||||||||||||||||||||||||||||||||||||||||||||||

class Game1State : public AppState
{
public:

	Game1State();

	DECLARE_APPSTATE_CLASS(Game1State)

	void enter();
	void createScene();
	void exit();
	bool pause();
	void resume();

	void movePlayerFromInput(); // move the player according to the key pressed
	void getInput();
    void buildGUI();

	void updatePlayerPosition(double timeSinceLastFrame);
	void updateHazardsAndBonusesCollisions();

	bool keyPressed(const OIS::KeyEvent &keyEventRef);
	bool keyReleased(const OIS::KeyEvent &keyEventRef);

	bool mouseMoved(const OIS::MouseEvent &arg);
	bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
	bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);

	void onLeftPressed(const OIS::MouseEvent &evt);

	void update(double timeSinceLastFrame);
	void updateMap(double timeSinceLastFrame);
	void checkVictoryOrLose();

	bool checkCollisionWithBlocks(Ogre::Vector3 oldPoint, Ogre::Vector3 &newPoint);
	Ogre::SceneNode* checkCollisionWithHazards(Ogre::AxisAlignedBox &box);
	Ogre::SceneNode* checkCollisionWithBonuses(Ogre::AxisAlignedBox &box);

private:
	void loadLevel1();

	void loseGame();
	void winGame();

	bool m_bQuit;
	bool playerFalling;

	float playerSpeedX, playerSpeedY, playerSpeedZ;

	OgreBites::ProgressBar* timeLeftBar;
};

//|||||||||||||||||||||||||||||||||||||||||||||||

#endif

//|||||||||||||||||||||||||||||||||||||||||||||||